﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="StackItemsControl.cs" company="">
//   
// </copyright>
// <summary>
//   The stack items control.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Libium.Controls
{
    using System.Windows.Forms;

    /// <summary>
    /// The stack items control.
    /// </summary>
    public partial class StackItemsControl : ItemsControl
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="StackItemsControl"/> class.
        /// </summary>
        public StackItemsControl()
        {
            InitializeComponent();
				ItemsPanel.SizeChanged += ItemsPanel_SizeChanged;
        }

		  void ItemsPanel_SizeChanged(object sender, System.EventArgs e)
		  {
			  ItemsPanel.SetBounds(ItemsPanel.Bounds.X, ItemsPanel.Bounds.Y, ItemsPanel.Bounds.Width, ItemsPanel.Bounds.Height);
			  ItemsPanel.PerformLayout();
			  this.PerformLayout();
		  }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The add item view.
        /// </summary>
        /// <param name="typeName">
        /// The type name.
        /// </param>
        /// <param name="itemControl">
        /// The item control.
        /// </param>
        /// <returns>
        /// The <see cref="Control"/>.
        /// </returns>
		  public override Control AddItemView(string typeName, Control itemControl)
		  {
			  itemControl.Dock = DockStyle.Top;
			  ItemsPanel.Controls.Add(itemControl);
			  itemControl.Show();
			  return itemControl;
		  }
		  public void EnsureScrollVisibleIfNeeded()
		  {
			  ItemsPanel.SetBounds(ItemsPanel.Bounds.X, ItemsPanel.Bounds.Y, ItemsPanel.Bounds.Width, ItemsPanel.Bounds.Height);
			  ItemsPanel.PerformLayout();
			  this.PerformLayout();
		  }
        /// <summary>
        /// The clear.
        /// </summary>
        public override void Clear()
        {
            ItemsPanel.Controls.Clear();
        }

        /// <summary>
        /// The delete item view.
        /// </summary>
        /// <param name="view">
        /// The view.
        /// </param>
        public override void DeleteItemView(Control view)
        {
            ItemsPanel.Controls.Remove(view);
        }

        #endregion

		  private void StackItemsControl_FocusedChanged(Views.IView obj)
		  {
			  if (ItemsPanel.Controls.Count > 0)
			  {
				  ItemsPanel.Controls[0].Select();
				  ItemsPanel.ScrollControlIntoView(ItemsPanel.Controls[0]);
			  }
			  return;
		  }

		  private void StackItemsControl_MouseMove(object sender, MouseEventArgs e)
		  {
			  System.Console.WriteLine();
		  }

		  private void StackItemsControl_MouseDown(object sender, MouseEventArgs e)
		  {
			  System.Console.WriteLine();
		  }

		  private void StackItemsControl_MouseUp(object sender, MouseEventArgs e)
		  {
			  System.Console.WriteLine();
		  }
    }
}